package com.ruoyi.project.app.interfaces;

import java.math.BigDecimal;

public interface BigDecimalHandleInterface {

	/**
	 * 处理金钱之差
	 *
	 * @param passive 被减数
	 * @param active  减数
	 * @param scale   保留位数
	 * @return 差
	 */
	default String handleSubStr(String passive, String active, int scale) {
		if (passive == null || "".equals(passive)) passive = "0";
		if (active == null || "".equals(active)) return passive;
		BigDecimal decimalP = new BigDecimal(passive);
		BigDecimal decimalA = new BigDecimal(active);
		BigDecimal decimal = decimalP.subtract(decimalA);
		return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
	}

	/**
	 * 处理金钱之差
	 *
	 * @param passive 被减数
	 * @param active  减数
	 * @param scale   保留位数
	 * @return 差
	 */
	default float handleSubVal(String passive, String active, int scale) {
		if (passive == null || "".equals(passive)) passive = "0";
		BigDecimal decimalP = new BigDecimal(passive);
		if (active == null || "".equals(active)) return decimalP.floatValue();
		BigDecimal decimalA = new BigDecimal(active);
		BigDecimal decimal = decimalA.subtract(decimalP);
		return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).floatValue();
	}

	/**
	 * 处理金钱之和
	 *
	 * @param passive 被加数
	 * @param active  加数
	 * @param scale   保留位数
	 * @return 差
	 */
	default String handleAddStr(String passive, String active, int scale) {
		if (passive == null || "".equals(passive)) passive = "0";
		if (active == null || "".equals(active)) return passive;
		BigDecimal decimalP = new BigDecimal(passive);
		BigDecimal decimalA = new BigDecimal(active);
		BigDecimal decimal = decimalP.add(decimalA);
		return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
	}

	/**
	 * 处理金钱之积
	 *
	 * @param passive 被
	 * @param active  主
	 * @param scale   保留位数
	 * @return 积
	 */
	default String handleMulStr(String passive, String active, int scale) {
		if (passive == null || "".equals(passive)) passive = "0";
		if (active == null || "".equals(active)) return passive;
		BigDecimal decimalAu = new BigDecimal(passive);
		BigDecimal decimalAd = new BigDecimal(active);
		BigDecimal decimal = decimalAu.multiply(decimalAd);
		return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
	}

	/**
	 * 处理金钱之积
	 *
	 * @param passive 被
	 * @param active  主
	 * @param scale   保留位数
	 * @return 积
	 */
	default float handleMulVal(String passive, String active, int scale) {
		if (passive == null || "".equals(passive)) passive = "0";
		BigDecimal decimalAu = new BigDecimal(passive);
		if (active == null || "".equals(active)) return decimalAu.floatValue();
		BigDecimal decimalAd = new BigDecimal(active);
		BigDecimal decimal = decimalAu.multiply(decimalAd);
		return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).floatValue();
	}

	/**
	 * 处理金钱之积
	 *
	 * @param passive 被加数
	 * @param active  加数
	 * @param scale   保留位数
	 * @return 积
	 */
	default String handleMulStr(Float passive, Float active, int scale) {
		if (passive == null) passive = 0f;
		if (active == null) return passive.toString();
		BigDecimal decimalP = new BigDecimal(passive);
		BigDecimal decimalA = new BigDecimal(active);
		BigDecimal decimal = decimalP.multiply(decimalA);
		return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
	}

}
